﻿CREATE TABLE [dbo].[text_Chapter] (
    [ChapterId]       UNIQUEIDENTIFIER CONSTRAINT [DF_text_Chapter_ChapterId] DEFAULT (newid()) NOT NULL,
    [ParentChapterId] UNIQUEIDENTIFIER NULL,
    [BookId]          UNIQUEIDENTIFIER NOT NULL,
    [HashTag]         NVARCHAR (128)   NOT NULL,
    [IsPublished]     BIT              NOT NULL,
    [Cost]            NVARCHAR (128)   NULL,
    [Order]           INT              NOT NULL,
    [Title]           NVARCHAR (MAX)   NULL,
    [Hint]            NVARCHAR (512)   NOT NULL,
    [UpdateDate]      DATETIME         CONSTRAINT [DF_text_Chapter_UpdateDate] DEFAULT (getutcdate()) NOT NULL,
    CONSTRAINT [PK_text_Chapter] PRIMARY KEY CLUSTERED ([ChapterId] ASC),
    CONSTRAINT [FK_text_Chapter_text_Book] FOREIGN KEY ([BookId]) REFERENCES [dbo].[text_Book] ([BookId]),
    CONSTRAINT [FK_text_Chapter_text_Chapter] FOREIGN KEY ([ParentChapterId]) REFERENCES [dbo].[text_Chapter] ([ChapterId]),
    CONSTRAINT [IX_HashTag] UNIQUE NONCLUSTERED ([HashTag] ASC),
    CONSTRAINT [IX_ParentChapterId_Order] UNIQUE NONCLUSTERED ([ParentChapterId] ASC, [Order] ASC, [BookId] ASC)
);





